package net.roobook.auth.service;


import net.roobook.auth.mapper.MenuMapper;
import net.roobook.auth.mapper.UserMapper;
import net.roobook.common.entity.system.SysMenu;
import net.roobook.common.entity.system.SysUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class UserService {
	@Autowired
	private UserMapper userMapper;
	@Autowired
	private MenuMapper menuMapper;
	/**
	 * 根据用户名查询用户实体
	 * @Author Roobook
	 * @date 2022/4/9
	 * @param username 用户名
	 * @return net.roobook.common.entity.system.SysUser
	 */
	public SysUser findByName(String username) {
		return userMapper.findByName(username);
	}

	/**
	 * 根据用户名查询用户权限
	 * @Author Roobook
	 * @date 2022/4/9
	 * @param username 用户名
	 * @return java.lang.String
	 */
	public String findUserPermissions(String username) {
		List<SysMenu> userPermissions = menuMapper.findUserPermissions(username);

/*		List<String> perms = new ArrayList<>();
		for (SysMenu m: userPermissions){
			perms.add(m.getPerms());
		}*/
		return userPermissions.stream().map(SysMenu::getPerms).collect(Collectors.joining(","));
	}
}
